//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <string.h>
#include <elatypes.h>

wchar_t* __cdecl wcscat(wchar_t* pDest, const wchar_t* pSource)
{
#ifdef _GNUC

#if defined(_x86)
    int temp0, temp1, temp2, temp3;
    ASM("repne;"
        "scasw;"
        "sub $2, %0;"//edi=edi-2
        "1:"
        "lodsw;"
        "stosw;"
        "testw %%ax,%%ax;"
        "jne 1b;"
        : "=D" (temp0), "=S" (temp1), "=a" (temp2), "=c" (temp3)
        : "0" (pDest), "1" (pSource), "2" (0), "3" (0xffffffffu)
        :"memory");

    return pDest;
#endif    //if defined(_x86)

//#if defined(_arm)
//    register wchar_t* __res;
//    asm __volatile__(
//    	"1:\tldrh r3, [r0], #2\n\t"
//    	"mov r3, r3, lsl #16\n\t"
//		"mov r3, r3, lsr #16\n\t"
//    	"cmp r3, #0\n\t"
//    	"bne 1b\n\t"
//    	"sub r0, r0, #2\n"
//        "2:\tldrh r2, [r1], #2\n\t"
//        "strh r2, [r0], #2\n\t"
//        "mov r2, r2, lsl #16\n\t"
//  "mov r2, r2, lsr #16\n\t"
//        "cmp r2, #0\n\t"
//        "bne 2b"
//        :"=r"(__res)
//        ::"r2", "r3");
//
//   return pDest;
//#endif    //if defined(_arm)

#endif    //if _GNUC

    wchar_t* p;
    for (p = pDest; *p != 0;++p) // find end of pDest
        ;
    while ((*p++= *pSource++) != 0) // copy pSource to end of pDest
        ;
    return pDest;
}
